Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How to fix the graphing line on math calculator with initial scale [Resolved]

Im currently building an math graphing calculator in discord.js, the graphing work fine on 1.0x scale but when im changing the scale the graphing line start not right with the axes, I saw it to be move to bottom-left not to be the center of the graph

function draw(tree) {
    var i = 0;
    dx = 1 / global_scale;

    var y;
    variables.x = minX;

    var width = canvas.width;

    while (isNaN((y = eval(tree))) && i < width) {
        variables.x = minX + i * dx;
        i++;
    }

    let previousY = (y - minY) * global_scale;

    for (; i < width; i++) {
        variables.x = minX + i * dx;
        y = eval(tree);

        if (isNaN(y)) {
            console.log(`discontinuity at x = ${x}`);
            while ((y = eval(tree)) === NaN && i < width) {
                variables.x = minX + i * dx;
                i++;
            }
            previousY = (y - minY) * global_scale;
            continue;
        }

        y = (y - minY) * global_scale;

        ctx.beginPath();
        ctx.moveTo(i - 1, previousY);
        ctx.lineTo(i, y);
        ctx.lineWidth = 2;
        ctx.stroke();
        previousY = y;
    }
}```

[The graphing when i do x^2 with 0.01 initial scale][1]

[The graphing when i do sin(x) with 0.01 initial scale][2]


and i wanna it to be something like this :
[The graphing when i do x^2 with 1.0 initial scale][3]


  [1]: https://i.stack.imgur.com/WTTl6.png
  [2]: https://i.stack.imgur.com/8fH4n.png
  [3]: https://i.stack.imgur.com/hefWl.png
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!